<template>
  用户登录
  <el-form :model="form" label-width="auto" style="max-width: 600px">
    <el-form-item label="用户名称">
      <el-input v-model="form.UserNick" />
    </el-form-item>
    <el-form-item label="用户密码">
      <el-input v-model="form.Password" type="password" />
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="onSubmit">登录</el-button>
      <el-button>重置</el-button>
    </el-form-item>
  </el-form>
</template>

<script setup lang='ts'>
//引入组件
import axios from 'axios';
import { ElMessage } from 'element-plus';
import { ref, reactive, onMounted } from 'vue'
import { apiInstance1 } from '@/services/api'

import { useRouter } from 'vue-router';
import { useCounterStore } from '@/stores/counter';

const counterStore = useCounterStore();
const router = useRouter();
//获取登录信息
const form = reactive({
  UserNick: "",
  Password: ""
})

const onSubmit = () => {
  apiInstance1.get('api/UserInfo/UserLogin', {
    params: {
      UserNick: form.UserNick,
      Password: form.Password
    }
  }).then(res => {
    console.log(res.data.list)
    counterStore.is_login = true;
    axios.defaults.headers.common["Authorization"] = "Bearer " + res.data.token;
    console.log(res.data.token)
    counterStore.userInfoId = res.data.list.userInfoId;
    counterStore.userName = res.data.list.userName;
    console.log(counterStore.userName)
    router.push('/Menu')
  })
}

</script>

<style>
.container {
  display: grid;
  place-items: center;
  /* 同时水平和垂直居中 */
  height: 100vh;
  /* 使容器高度为视口高度 */
}

.content {
  text-align: center;
  /* 内容居中对齐 */
}
</style>
